#include "rclcpp/rclcpp.hpp"

//定义一个类PersionNode继承于Node
class PersionNode : public rclcpp::Node
{
private:
//声明
    std::string name_;
    int age_;

public:
    PersionNode(const std::string &node_name, const std::string &name, const int &age)
    :Node(node_name)/*调用父类的构造函数*/
    {
        this->name_ = name;
        this->age_ = age;
    }

    void eat(const std::string &food_name)
    {
        RCLCPP_INFO(this->get_logger(), "我是%s, 今年%d岁了, 喜欢吃%s。", this->name_.c_str(), this->age_, food_name.c_str());
        //注：.c_str()返回的是char*类型的数据
    };
};

int main(int argc, char** argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<PersionNode>("persion_node", "张三", 16);
    RCLCPP_INFO(node->get_logger(), "C++");
    node->eat("鱼香螺丝");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
